function load() {

    listModel.clear();

    var db = openDatabaseSync("cuteftp", "1.0", "cuteftp settings", 1000000);
    var data =  {"m_title": "New...", "m_ip":"Add a new connection", "m_port":"","m_user":"","m_password":""}
    listModel.append(data);


    db.transaction(function(tx) {
                       tx.executeSql('CREATE TABLE IF NOT EXISTS ips(name TEXT PRIMARY KEY, ip TEXT, port INTEGER, user TEXT, password TEXT)');

                       var rs = tx.executeSql('SELECT * FROM ips');
                       for(var i = 0; i < rs.rows.length; i++)
                       {
                           var item = rs.rows.item(i);
                           console.debug("read "+item.name);

                           var dbData = {"m_title": item.name, "m_ip":item.ip, "m_port":item.port,"m_user":item.user,"m_password":item.password}
                           listModel.append(dbData);
                       }

                   });


}

//==================================================================================

function save() {


    console.debug("save");
    var name = nameId.text;
    var ip = ipId.text;
    var port = portId.text;
    var user = userId.text;
    var password = passwordId.text

    var data = [name,ip,port,user,password];

    var db = openDatabaseSync("cuteftp", "1.0", "cuteftp settings", 1000000);

    db.transaction(
                function(tx) {
                    // Create the database if it doesn't already exist
                    tx.executeSql('CREATE TABLE IF NOT EXISTS ips(name TEXT PRIMARY KEY, ip TEXT, port INTEGER, user TEXT, password TEXT)');

                    try {
                        tx.executeSql('INSERT INTO ips VALUES(?,?,?,?,?)', data);
                        load();
                        dialog.show = false;

                    }
                    catch (err)
                    {

                        console.log(err);

                    }

                });
}


function remove()
{
    var name = listModel.get(view.currentIndex).m_title;
    console.debug("remove"+name);

    var db = openDatabaseSync("cuteftp", "1.0", "cuteftp settings", 1000000);
    db.transaction(
                function(tx) {

                    try {
                        tx.executeSql("DELETE from ips WHERE name='"+name+"'");
                        removeDialog.show=false;
                        load();
                    }
                    catch (err)
                    {

                        console.log(err.DATABASE_ERR);

                    }

                });


}
